import {
  ConditionalItem,
  featureFilteredArray,
  FeatureManager,
  ICurve,
  STATE,
  useCommandManager,
} from '@amcax/base';
import {
  CmdButton,
  CmdDivider,
  CmdSplitButton,
  CmdTabItem,
  CmdTabs,
  CmdUpTabs,
} from '@app-cad/components/CommandBar';
import { userEvents } from '@app-cad/module';

import { SKETCH_EVENT } from '@app-cad/common/Constants';
import { csEvent } from '@app-cad/common/events/EventCenter';
import { useTools } from '@app-cad/common/hooks/useTools';

// Common CMD
import { cmdCsys } from '@app-cad/common/commands/cmd-csys';
import { cmdDesignTable } from '@app-cad/common/commands/cmd-design-table';
import { cmdExport } from '@app-cad/common/commands/cmd-export';
import { cmdImport } from '@app-cad/common/commands/cmd-import';
import { cmdRedo } from '@app-cad/common/commands/cmd-redo';
import { cmdUndo } from '@app-cad/common/commands/cmd-undo';
import { cmdSettings } from '@app-cad/common/commands/cmd-settings';

// SKETCH CMD
import {
  cmdArc,
  cmdThreePointArc,
} from '@app-cad-env/nextcad/commands/sketch/cmd-arc';
import { cmdArray } from '@app-cad-env/nextcad/commands/sketch/cmd-array';
import { cmdCircleArray } from '@app-cad-env/nextcad/commands/sketch/cmd-array/circleIndex';
import { cmdChamfer as cmdSketchChamfer } from '@app-cad-env/nextcad/commands/sketch/cmd-chamfer';
import {
  cmdCircle,
  cmdThreePointCircle,
  cmdThreeLineCircle,
} from '@app-cad-env/nextcad/commands/sketch/cmd-circle';
import { cmdConstranit } from '@app-cad-env/nextcad/commands/sketch/cmd-constraint';
import { cmdDivision as cmdSketchDivision } from '@app-cad-env/nextcad/commands/sketch/cmd-division';
import { cmdEllipse } from '@app-cad-env/nextcad/commands/sketch/cmd-ellipse';
import { cmdEllipseArc } from '@app-cad-env/nextcad/commands/sketch/cmd-ellipse-arc';
import { cmdFillet as cmdSketchFillet } from '@app-cad-env/nextcad/commands/sketch/cmd-fillet';
import { cmdLine as cmdSketchLine } from '@app-base/environments/nextcad/commands/sketch/cmd-line/2point';
import { cmdMidPointLine as cmdSketchMidPointLine } from '@app-base/environments/nextcad/commands/sketch/cmd-line/mid-point';
import { cmdMirror as cmdSketchMirror } from '@app-cad-env/nextcad/commands/sketch/cmd-mirror';
import { cmdOffset as cmdSketchOffset } from '@app-cad-env/nextcad/commands/sketch/cmd-offset';
import { cmdPoint as cmdSketchPoint } from '@app-cad-env/nextcad/commands/sketch/cmd-point';
import { cmdMultipleLine as cmdMultipleLine2 } from '@app-cad-env/nextcad/commands/sketch/cmd-polygon';
import {
  cmdCenter,
  cmdDiagonal,
  cmdParallel,
  cmdThreeCenterPoint,
  cmdThreePoint,
} from '@app-cad-env/nextcad/commands/sketch/cmd-rectangle/index';
import { cmdRedo as cmdSketchRedo } from '@app-cad-env/nextcad/commands/sketch/cmd-redo';
import { cmdSketchOut } from '@app-cad-env/nextcad/commands/sketch/cmd-sketch-out';
import { cmdSpline as cmdSketchSpline } from '@app-cad-env/nextcad/commands/sketch/cmd-spline';
import { cmdTrim } from '@app-cad-env/nextcad/commands/sketch/cmd-trim';
import { cmdUndo as cmdSketchUndo } from '@app-cad-env/nextcad/commands/sketch/cmd-undo';
import { DimAngle } from '@app-cad-env/nextcad/commands/sketch/dimAngle/index';
import { DimDiameter } from '@app-cad-env/nextcad/commands/sketch/dimDiameter/index';
import { DimHorizontal } from '@app-cad-env/nextcad/commands/sketch/dimHorizontal/index';
import { DimRadius } from '@app-cad-env/nextcad/commands/sketch/dimRadius/index';
import { DimVertical } from '@app-cad-env/nextcad/commands/sketch/dimVertical/index';
import { DimLinear } from '@app-cad/environments/nextcad/commands/sketch/dimlinear/index';

// FEATURE CMD
import { cmdCircularArray } from '@app-cad-env/nextcad/commands/feature/cmd-array-circle';
import { cmdLinearArray } from '@app-cad-env/nextcad/commands/feature/cmd-array-linear';
import { cmdChamfer } from '@app-cad-env/nextcad/commands/feature/cmd-chamfer';
// import { cmdCopy } from '@app-cad-env/nextcad/commands/feature/cmd-copy';
import { cmdCutter } from '@app-cad-env/nextcad/commands/feature/cmd-cutter';
import { cmdDraft } from '@app-cad-env/nextcad/commands/feature/cmd-draft';
import { cmdFillet as cmdFeatureFillet } from '@app-cad-env/nextcad/commands/feature/cmd-fillet';
import { cmdLoft } from '@app-cad-env/nextcad/commands/feature/cmd-loft';
import { cmdLoftCut } from '@app-cad-env/nextcad/commands/feature/cmd-loft-cut';
import { cmdRevol } from '@app-cad-env/nextcad/commands/feature/cmd-revol';
import { cmdShell } from '@app-cad-env/nextcad/commands/feature/cmd-shell';
import { cmdSweep } from '@app-cad-env/nextcad/commands/feature/cmd-sweep';
import { cmdThickness } from '@app-cad-env/nextcad/commands/feature/cmd-thickness';
import { cmdSketchIn } from '@app-cad/environments/nextcad/commands/feature/cmd-sketch-in';
// import { cmdEllipse } from '../../commands/feature/cmd-ellipse';
import { cmdTorus } from '../../commands/feature/cmd-torus';
// import { cmdPrism } from '../../commands/feature/cmd-prism';
import { cmdCylinder } from '../../commands/feature/cmd-cylinder';
// import { cmdWedge } from '../../commands/feature/cmd-wedge';
// CURVED CMD
import { cmdCurvatureComb } from '@app-base/environments/nextcad/commands/curved/cmd-curvature-comb';
import { cmdBlendSurface } from '@app-cad-env/nextcad/commands/curved/cmd-blend-surface';
import { cmdSurfaceSpliter } from '@app-base/environments/nextcad/commands/curved/cmd-surface-splitter';
import { cmdDisplaySweepSurface } from '@app-cad-env/nextcad/commands/curved/cmd-display-sweep-surface';
import { cmdDoubleTrackSweep } from '@app-cad-env/nextcad/commands/curved/cmd-double-track-sweep';
import { cmdExtrudeSurface } from '@app-cad-env/nextcad/commands/curved/cmd-extrude-surface';
import { cmdFaceJoin } from '@app-cad-env/nextcad/commands/curved/cmd-face-join';
import { cmdFaceSew } from '@app-cad-env/nextcad/commands/curved/cmd-face-sew';
import { cmdFillSurface } from '@app-cad-env/nextcad/commands/curved/cmd-fill-surface';
import { cmdLoftSurface } from '@app-cad-env/nextcad/commands/curved/cmd-loft-surface';
import { cmdMatchSurface } from '@app-cad-env/nextcad/commands/curved/cmd-match-surface';
import { cmdMface } from '@app-cad-env/nextcad/commands/curved/cmd-mface';
import { cmdCurveMirror as cmdMirror } from '@app-cad-env/nextcad/commands/curved/cmd-mirror';
import { cmdMonorailSweep } from '@app-cad-env/nextcad/commands/curved/cmd-monorail-sweep';
import { cmdMove } from '@app-cad-env/nextcad/commands/curved/cmd-move';
import { cmdMsolid } from '@app-cad-env/nextcad/commands/curved/cmd-msolid';
import { cmdSurfaceRotate as cmdRotate } from '@app-cad-env/nextcad/commands/curved/cmd-rotate';
import { cmdRotateSurface } from '@app-cad-env/nextcad/commands/curved/cmd-rotate-surface';
import { cmdSetPosition } from '@app-cad-env/nextcad/commands/curved/cmd-set-position';
import { cmdSurfaceTranslation } from '@app-cad-env/nextcad/commands/curved/cmd-surface-translation';
import { cmdSurfaceTrim } from '@app-cad-env/nextcad/commands/curved/cmd-surface-trim';

// Tools CMD
import { cmdBoolean } from '@app-cad-env/nextcad/commands/curved/cmd-boolean';
import { cmdBoundary } from '@app-cad-env/nextcad/commands/curved/cmd-boundary';
import { cmdGeomBox } from '@app-cad-env/nextcad/commands/curved/cmd-geom-box';
import { cmdPick } from '@app-cad-env/nextcad/commands/curved/cmd-pick';
import { cmdCurveScale } from '@app-cad-env/nextcad/commands/curved/cmd-scale';
import { cmdStiffener } from '@app-cad-env/nextcad/commands/feature/cmd-stiffener';

// Wireframe CMD
import { cmdBlendCurve } from '@app-cad-env/nextcad/commands/curved/cmd-blend-curve';
import { cmdCross2 } from '@app-cad-env/nextcad/commands/curved/cmd-cross2';
import { cmdCurveBreak } from '@app-cad-env/nextcad/commands/curved/cmd-curve-break';
import { cmdCurveConic } from '@app-cad-env/nextcad/commands/curved/cmd-curve-conic';
import { cmdCurveHybrid } from '@app-cad-env/nextcad/commands/curved/cmd-curve-hybrid';
import { cmdCurveIso } from '@app-cad-env/nextcad/commands/curved/cmd-curve-iso';
import { cmdCurveJoin } from '@app-cad-env/nextcad/commands/curved/cmd-curve-join';
import { cmdExtendCurve } from '@app-cad-env/nextcad/commands/curved/cmd-extend-curve';
import { cmdFillet } from '@app-cad-env/nextcad/commands/curved/cmd-fillet';
import { cmdMatchCurve } from '@app-cad-env/nextcad/commands/curved/cmd-match-curve';
import { cmdOffsetCurve } from '@app-cad-env/nextcad/commands/curved/cmd-offest-curve';
import { cmdVertexExtremal } from '@app-cad-env/nextcad/commands/curved/cmd-point-extremal';
import { cmdRebuildCurve } from '@app-cad-env/nextcad/commands/curved/cmd-rebuild-curve';
import { cmdSmooth } from '@app-cad-env/nextcad/commands/curved/cmd-smooth';
import { cmdSpline } from '@app-cad-env/nextcad/commands/curved/cmd-spline';
import { cmdPoint } from '@app-cad/environments/nextcad/commands/curved/cmd-point';
import { useEffect, useState } from 'react';
import { cmdFourPointSurface } from '../../commands/curved/cmd-four-point-surface';
import { lineAttribute } from '../../commands/sketch/cmd-attribute';
import { LinePickEve } from '../../commands/sketch/cmd-line/types';
import {
  SKETCH_CENTEREVENTS,
  sketchEventCenter,
} from '../../events/SketchEventCenter';

import { cmdRebuildSurface } from '../../commands/curved/cmd-surface-rebuild';
// import { cmdCurvedBox } from '../../commands/curved/cmd-box';
import { cmdChangeColor } from '@app-base/common/commands/cmd-change-color';
import { cmdMeasure } from '@app-base/common/commands/cmd-measure';
import { cmdParameterObject } from '@app-base/common/commands/cmd-parameter-object';
import { cmdParameterSet } from '@app-base/common/commands/cmd-parameter-set';
import { CommandBarParams } from '@app-base/types';
import { cmdLawCurve } from '@app-cad/environments/nextcad/commands/curved/cmd-law-curve';
import { cmdPlane } from '@app-cad/environments/nextcad/commands/curved/cmd-plane';
import { cmdCurveAffine } from '../../commands/curved/cmd-affine';
import { cmdInverseSurface } from '../../commands/curved/cmd-inverse-surface';
import { cmdAnalyse } from '../../commands/curved/cmd-analyse';
import { cmdArcOfCircle } from '../../commands/curved/cmd-arc';
import { cmdCircularSweep } from '../../commands/curved/cmd-circle-sweep';
import { cmdCopyPlane } from '../../commands/curved/cmd-copy-plane';
import { cmdCopyVertex } from '../../commands/curved/cmd-copy-vertex';
import { cmdConicalSweep } from '../../commands/curved/cmd-curve-conic-sweep';
import { cmdExplode } from '../../commands/curved/cmd-explode';
import { cmdExplodeSurface } from '../../commands/curved/cmd-explode-surface';
import { cmdExtendSurface } from '../../commands/curved/cmd-extend-surface';
import { cmdGeomSet } from '../../commands/curved/cmd-geom-set';
import { cmdLine } from '../../commands/curved/cmd-line';
import { cmdLinearSweep } from '../../commands/curved/cmd-linear-sweep';
import { cmdPolyline } from '../../commands/curved/cmd-polyline';
import { cmdProjection } from '../../commands/curved/cmd-projection';
import { cmdRevolveSweep } from '../../commands/curved/cmd-revolve-sweep';
import { cmdRuledCurface } from '../../commands/curved/cmd-ruled-surface';
import { cmdSurfaceUntrim } from '../../commands/curved/cmd-untrim';
import { cmdBox } from '../../commands/feature/cmd-box';
import { cmdCone } from '../../commands/feature/cmd-cone';
import { cmdCylinderSurface } from '../../commands/feature/cmd-cylinder-surface';
import { cmdDeleteFace } from '../../commands/feature/cmd-delete-face';
import { cmdExtrudeCut } from '../../commands/feature/cmd-extrude/cut';
import { cmdStretch } from '../../commands/feature/cmd-extrude/extrude';
import { cmdHelix } from '../../commands/feature/cmd-helix';
import { cmdHole } from '../../commands/feature/cmd-hole';
import { cmdThread } from '../../commands/feature/cmd-thread';
import { cmdImportAirfoil } from '../../commands/feature/cmd-import-airfoilPoints';
import { cmdPyramid } from '../../commands/feature/cmd-pyramid/cmd-pyramid';
import { cmdRepairFace } from '../../commands/feature/cmd-repair-face';
import { cmdReplaceFace } from '../../commands/feature/cmd-replace-face';
import { cmdRevolCut } from '../../commands/feature/cmd-revol-cut';
import { cmdSolidMix } from '../../commands/feature/cmd-solid-mix';
import { cmdSphere } from '../../commands/feature/cmd-sphere';
import { cmdSphereSurface } from '../../commands/feature/cmd-sphere-surface';
import { cmdSplitFace } from '../../commands/feature/cmd-split-face';
import { cmdSweepCut } from '../../commands/feature/cmd-sweep-cut';
import { cmdThicknessCut } from '../../commands/feature/cmd-thickness-cut';
import { cmdTube } from '../../commands/feature/cmd-tube';
import {
  cmdCenterPointArcRabbet,
  cmdThreePointArcRabbet,
} from '../../commands/sketch/cmd-arc-rabbet';
import {
  cmdCenterLineRabbet,
  cmdCenterPointCenterLineRabbet,
} from '../../commands/sketch/cmd-center-line-rabbet';
import { Dimintegration } from '../../commands/sketch/cmd-integration-dim';
import { cmdIntersect3D } from '../../commands/sketch/cmd-intersect-3d';
import { cmdTangencyArc } from '../../commands/sketch/cmd-tangency-arc';
import { cmdCurveParallel } from '../../commands/curved/cmd-curve-parallel';
import { cmdMaterial } from '../../commands/tools/cmd-material';
import { cmdProject3D } from '../../commands/sketch/cmd-project-3d';
import { cmdSketchTransform } from '../../commands/sketch/cmd-transform';
import { cmdGenerateDrafting } from '../../commands/tools/cmd-generate-drafting';
import { cmdSketchOutline } from '../../commands/sketch/cmd-outline';
import { cmdAirfoil } from '../../commands/feature/cmd-create-airfoil';
import { isElectronEnv } from '@app-base/common/utils/isElectronEnv';

export default function CommandBar(props: CommandBarParams) {
  const { resetCmd, invokeCmd } = useCommandManager();
  const [sketchInStatus, setSketchInStatus] = useState(false);
  const { style: cmdStyle } = props;
  useEffect(() => {
    sketchEventCenter().on(
      SKETCH_CENTEREVENTS.PICK_SELECTED_INFO,
      getPickedInfo,
    );
    registerEvents();
    return () => {
      sketchEventCenter().off(
        SKETCH_CENTEREVENTS.PICK_SELECTED_INFO,
        getPickedInfo,
      );
      unRegisterEvents();
    };
  }, []);

  const getPickedInfo = (data: ICurve) => {
    if (
      sketchEventCenter().state === STATE.DEFAULT &&
      csEvent().state === STATE.DEFAULT
    ) {
      if (data.type !== 'Point') {
        invokeCmd(lineAttribute);
        setTimeout(() => {
          sketchEventCenter().emit(LinePickEve.SKETCH_SELECT_PICK, data);
        });
      } else {
        sketchEventCenter().emit(SKETCH_CENTEREVENTS.MOUSEDOWNMOVE);
      }
    }
  };
  const registerEvents = () => {
    userEvents.on(SKETCH_EVENT.SKETCH_EVENT_CHANGE, onEventCenterChange);
  };

  const { picker } = useTools();

  const onEventCenterChange = ({ type }: { type: string; oldId?: string }) => {
    if (type === 'sketchIn') {
      setSketchInStatus(true);
      picker.clearPickedObjects();
    } else if (type === 'sketchOut') {
      setSketchInStatus(false);
    }
  };
  const unRegisterEvents = () => {
    userEvents.off(SKETCH_EVENT.SKETCH_EVENT_CHANGE, onEventCenterChange);
  };

  const tabItems: CmdTabItem[] = [
    {
      id: 'standard',
      label: '标准',
      children: (
        <>
          {FeatureManager.isFeatureEnabled('electron-show-port') ? (
            <CmdButton cmd={cmdImport} />
          ) : null}
          {FeatureManager.isFeatureEnabled('electron-show-port') ? (
            <CmdButton cmd={cmdExport} />
          ) : null}
          {FeatureManager.isFeatureEnabled('generate-drafting') ? (
            <CmdButton cmd={cmdGenerateDrafting} />
          ) : null}
          <CmdButton
            cmd={cmdSettings}
            featureEnableCode='cmd-standard-setting'
          />
          {FeatureManager.isFeatureEnabled('electron-show-port') ? (
            <CmdDivider />
          ) : null}
          {!sketchInStatus && (
            <>
              <CmdButton cmd={cmdUndo} />
              <CmdButton cmd={cmdRedo} />
            </>
          )}
          {sketchInStatus && (
            <>
              <CmdButton cmd={cmdSketchUndo} />
              <CmdButton cmd={cmdSketchRedo} />
            </>
          )}
        </>
      ),
    },
    {
      id: 'wireframe',
      label: '线框',
      children: (
        <>
          <CmdButton cmd={cmdCsys} />
          <CmdDivider />
          <CmdSplitButton
            key='wireframe_points'
            cmds={[cmdPoint, cmdVertexExtremal, cmdCopyVertex]}
            cmdStyle={cmdStyle}
          />
          {FeatureManager.isFeatureEnabled('polyline') ? (
            <CmdSplitButton
              cmds={[cmdLine, cmdPolyline]}
              cmdStyle={cmdStyle}
            />
          ) : (
            <CmdButton cmd={cmdLine} />
          )}
          <CmdButton cmd={cmdPlane} />
          {FeatureManager.isFeatureEnabled('cmd-curve-parallel') ? (
            <CmdButton cmd={cmdCurveParallel} />
          ) : (
            ''
          )}
          {FeatureManager.isFeatureEnabled('copy-plane') ? (
            <CmdButton cmd={cmdCopyPlane} />
          ) : (
            ''
          )}
          <CmdSplitButton cmds={[cmdArcOfCircle, cmdFillet]} />
          <CmdSplitButton
            cmds={[cmdSpline, cmdCurveConic, cmdCurveIso, cmdHelix]}
            cmdStyle={cmdStyle}
          />
          {FeatureManager.isFeatureEnabled('law-curve') ? (
            <CmdButton cmd={cmdLawCurve} />
          ) : (
            ''
          )}
          <CmdSplitButton
            cmds={[cmdBlendCurve, cmdMatchCurve]}
            cmdStyle={cmdStyle}
          />
          <CmdSplitButton
            cmds={[cmdCurveHybrid, cmdOffsetCurve]}
            cmdStyle={cmdStyle}
          />
          <CmdButton cmd={cmdProjection} />
          <CmdButton cmd={cmdCross2} />
          <CmdSplitButton
            cmds={[cmdCurveJoin, cmdSmooth, cmdRebuildCurve]}
            cmdStyle={cmdStyle}
          />
          <CmdSplitButton
            cmds={[cmdCurveBreak, cmdExplode]}
            cmdStyle={cmdStyle}
          />
          <CmdButton cmd={cmdExtendCurve} />
        </>
      ),
    },
    {
      id: 'sketch',
      label: '草图',
      children: (
        <>
          <CmdButton cmd={sketchInStatus ? cmdSketchOut : cmdSketchIn} />
          <CmdDivider />
          <CmdButton cmd={cmdSketchPoint} />
          <CmdSplitButton
            cmds={featureFilteredArray([
              cmdCircle,
              new ConditionalItem('three-point-circle', cmdThreePointCircle),
              cmdThreeLineCircle,
            ])}
            cmdStyle={cmdStyle}
          />
          <CmdButton cmd={cmdEllipse} />
          {FeatureManager.isFeatureEnabled('ellipse-arc') ? (
            <CmdButton cmd={cmdEllipseArc} />
          ) : null}
          <CmdSplitButton
            cmdStyle={cmdStyle}
            cmds={featureFilteredArray([
              cmdArc,
              new ConditionalItem('three-point-arc', cmdThreePointArc),
              cmdTangencyArc,
            ])}
          />
          <CmdSplitButton cmds={[cmdSketchLine, cmdSketchMidPointLine]} />
          <CmdButton cmd={cmdMultipleLine2} />
          <CmdButton cmd={cmdSketchOutline} />
          <CmdSplitButton
            cmdStyle={cmdStyle}
            cmds={featureFilteredArray([
              cmdDiagonal,
              cmdCenter,
              cmdParallel,
              cmdThreePoint,
              new ConditionalItem(
                'three-point-center-rectangle',
                cmdThreeCenterPoint,
              ),
            ])}
          />
          {FeatureManager.isOneFeatureEnabled([
            'center-line-rabbet',
            'center-point-center-line-rabbet',
            'three-point-arc-rabbet',
            'center-point-arc-rabbet',
          ]) ? (
            <CmdSplitButton
              cmds={featureFilteredArray([
                new ConditionalItem('center-line-rabbet', cmdCenterLineRabbet),
                new ConditionalItem(
                  'center-point-center-line-rabbet',
                  cmdCenterPointCenterLineRabbet,
                ),
                new ConditionalItem(
                  'three-point-arc-rabbet',
                  cmdThreePointArcRabbet,
                ),
                new ConditionalItem(
                  'center-point-arc-rabbet',
                  cmdCenterPointArcRabbet,
                ),
              ])}
            />
          ) : null}
          <CmdButton cmd={cmdSketchSpline} />
          <CmdButton cmd={cmdSketchMirror} />
          <CmdButton cmd={cmdTrim} />
          <CmdButton cmd={cmdSketchFillet} />
          <CmdButton cmd={cmdSketchChamfer} />
          <CmdButton cmd={cmdSketchDivision} />
          <CmdButton cmd={cmdSketchOffset} />
          <CmdSplitButton
            cmds={[cmdArray, cmdCircleArray]}
            cmdStyle={cmdStyle}
          />
          <CmdButton cmd={cmdConstranit} />
          <CmdButton cmd={cmdSketchTransform} />
          {FeatureManager.isFeatureEnabled('dimensional-constraint') ? (
            <CmdButton cmd={Dimintegration} />
          ) : (
            <CmdSplitButton
              cmdStyle={cmdStyle}
              cmds={[
                DimLinear,
                DimHorizontal,
                DimVertical,
                DimDiameter,
                DimRadius,
                DimAngle,
              ]}
            />
          )}
          {FeatureManager.isFeatureEnabled('sketch-intersect3d') && (
            <CmdButton cmd={cmdIntersect3D} />
          )}
          {FeatureManager.isFeatureEnabled('sketch-project-3d') && (
            <CmdButton cmd={cmdProject3D} />
          )}
        </>
      ),
    },
    {
      id: 'feature',
      label: '特征',
      children: (
        <>
          <CmdSplitButton
            cmds={[cmdStretch, cmdExtrudeCut]}
            cmdStyle={cmdStyle}
          />
          <CmdSplitButton
            cmds={[cmdRevol, cmdRevolCut]}
            cmdStyle={cmdStyle}
          />
          <CmdSplitButton
            cmdStyle={cmdStyle}
            cmds={featureFilteredArray([
              cmdLoft,
              new ConditionalItem('loft-cut', cmdLoftCut),
            ])}
          />
          <CmdSplitButton
            cmdStyle={cmdStyle}
            cmds={featureFilteredArray([
              cmdSweep,
              new ConditionalItem('sweep-cut', cmdSweepCut),
            ])}
          />
          <CmdButton cmd={cmdShell} />
          {FeatureManager.isFeatureEnabled('stiffence') ? (
            <CmdButton cmd={cmdStiffener} />
          ) : null}
          <CmdButton cmd={cmdMsolid} />
          <CmdSplitButton
            cmds={[cmdThickness, cmdThicknessCut]}
            cmdStyle={cmdStyle}
          />
          <CmdButton cmd={cmdCutter} />
          <CmdButton cmd={cmdDraft} />
          <CmdSplitButton
            cmds={[cmdFeatureFillet, cmdChamfer]}
            cmdStyle={cmdStyle}
          />
          <CmdSplitButton
            cmdStyle={cmdStyle}
            cmds={featureFilteredArray([
              new ConditionalItem('regular-box', cmdBox),
              cmdTube,
              new ConditionalItem('regular-sphere', cmdSphere),
              cmdCone,
              new ConditionalItem('regular-torus', cmdTorus),
              new ConditionalItem('regular-cylinder', cmdCylinder),
              // cmdWedge,
              cmdPyramid,
            ])}
          />
          <CmdSplitButton
            cmdStyle={cmdStyle}
            cmds={featureFilteredArray([
              new ConditionalItem('delete-face', cmdDeleteFace),
              new ConditionalItem('repair-face', cmdRepairFace),
              new ConditionalItem('replace-face', cmdReplaceFace),
              new ConditionalItem('split-face', cmdSplitFace),
            ])}
          />
          <CmdButton cmd={cmdBoolean} />

          {FeatureManager.isFeatureEnabled('cmd-solid-mix') ? (
            <CmdButton cmd={cmdSolidMix} />
          ) : null}
          {FeatureManager.isFeatureEnabled('hole') ? (
            <CmdButton cmd={cmdHole} />
          ) : null}
          {FeatureManager.isFeatureEnabled('cmd-thread') ? (
            <CmdButton cmd={cmdThread} />
          ) : null}
        </>
      ),
    },
    {
      id: 'surface',
      label: '曲面',
      children: (
        <>
          <CmdButton cmd={cmdExtrudeSurface} />
          <CmdButton cmd={cmdLoftSurface} />
          <CmdButton cmd={cmdFourPointSurface} />
          <CmdSplitButton
            cmdStyle={cmdStyle}
            cmds={[
              cmdLinearSweep,
              cmdDisplaySweepSurface,
              cmdCircularSweep,
              cmdMonorailSweep,
              cmdDoubleTrackSweep,
              cmdRevolveSweep,
              cmdConicalSweep,
            ]}
          />
          <CmdSplitButton
            cmdStyle={cmdStyle}
            cmds={featureFilteredArray([
              new ConditionalItem('cylinder-surface', cmdCylinderSurface),
              new ConditionalItem('sphere-surface', cmdSphereSurface),
            ])}
          />
          <CmdButton cmd={cmdFillSurface} />
          <CmdSplitButton
            cmdStyle={cmdStyle}
            cmds={[cmdSurfaceTranslation, cmdBlendSurface, cmdMatchSurface]}
          />
          <CmdButton cmd={cmdMface} />
          <CmdSplitButton
            cmds={[cmdFaceSew, cmdFaceJoin]}
            cmdStyle={cmdStyle}
          />
          <CmdSplitButton
            cmdStyle={cmdStyle}
            cmds={featureFilteredArray([
              new ConditionalItem('spliter-surface', cmdSurfaceSpliter),
              new ConditionalItem('trim-surface', cmdSurfaceTrim),
              new ConditionalItem('rotate-surface', cmdRotateSurface),
              cmdSurfaceUntrim,
            ])}
          />
          <CmdButton cmd={cmdRebuildSurface} />
          <CmdButton cmd={cmdExtendSurface} />
          <CmdButton cmd={cmdExplodeSurface} />
          {FeatureManager.isFeatureEnabled('ruled-curface') ? (
            <CmdButton cmd={cmdRuledCurface} />
          ) : null}
        </>
      ),
    },
    {
      id: 'transformation',
      label: '变换',
      children: (
        <>
          {/* <CmdButton cmd={cmdCopy} /> */}
          <CmdButton cmd={cmdMove} />
          <CmdButton cmd={cmdRotate} />
          <CmdButton cmd={cmdMirror} />
          <CmdButton cmd={cmdSetPosition} />
          {FeatureManager.isFeatureEnabled('tools-array-linear') ? (
            <CmdButton cmd={cmdLinearArray} />
          ) : null}
          {FeatureManager.isFeatureEnabled('tools-array-circular') ? (
            <CmdButton cmd={cmdCircularArray} />
          ) : null}
          <CmdDivider />
          <CmdButton cmd={cmdCurveScale} />
          <CmdButton cmd={cmdCurveAffine} />
          <CmdButton cmd={cmdPick} />
          <CmdButton cmd={cmdBoundary} />
          <CmdButton cmd={cmdInverseSurface} />
        </>
      ),
    },
    {
      id: 'tools',
      label: '工具',
      children: (
        <>
          <CmdButton cmd={cmdGeomBox} />
          {FeatureManager.isFeatureEnabled('cmd-geom-set') && (
            <CmdButton cmd={cmdGeomSet} />
          )}
          {FeatureManager.isFeatureEnabled('cmd-measure') && (
            <CmdButton cmd={cmdMeasure} />
          )}
          <CmdButton cmd={cmdAnalyse} />
          {FeatureManager.isFeatureEnabled('cmd-curvature-comb') && (
            <CmdButton cmd={cmdCurvatureComb} />
          )}
          {FeatureManager.isFeatureEnabled('cmd-parameter') && (
            <>
              <CmdButton cmd={cmdParameterSet} />
              <CmdButton cmd={cmdParameterObject} />
            </>
          )}
          {FeatureManager.isFeatureEnabled('cmd-design-table') && (
            <CmdButton cmd={cmdDesignTable} />
          )}
          <CmdButton cmd={cmdChangeColor} />
          {FeatureManager.isFeatureEnabled('cmd-material') && (
            <CmdButton cmd={cmdMaterial} />
          )}
        </>
      ),
    },
    !isElectronEnv() && {
      id: 'plugin',
      label: '插件',
      children: (
        <>
          {FeatureManager.isFeatureEnabled('cmd-import-airfoilPoints') && (
            <CmdButton cmd={cmdImportAirfoil} />
          )}
          {FeatureManager.isFeatureEnabled('cmd-create-airfoil') && (
            <CmdButton cmd={cmdAirfoil} />
          )}
        </>
      ),
    },
  ];
  const onTabSwitch = async (itemId: string) => {
    resetCmd();
    if (itemId !== 'sketch' && sketchInStatus) {
      await invokeCmd(cmdSketchOut);
    }
  };

  if (cmdStyle === 'down') {
    return (
      <CmdTabs
        items={tabItems}
        onTabSwitch={onTabSwitch}
      />
    );
  }

  return (
    <CmdUpTabs
      items={tabItems}
      onTabSwitch={onTabSwitch}
    />
  );
}
